package com.modular.event.tool;

import cn.hutool.core.collection.ListUtil;
import cn.hutool.log.StaticLog;

import java.util.*;

/**
 * 雨量计算工具
 */
public class ToolRain {

    private static final Map<Integer, Integer> RAIN_LEVEL = new LinkedHashMap<>();

    private static final List<String> LEVEL_NAME = ListUtil.of("", "晴", "小雨", "中雨", "大雨", "暴雨", "大暴雨", "特大暴雨", "罕见暴雨");

    static {
        // 12h 最大值
        RAIN_LEVEL.put(1, 1);
        RAIN_LEVEL.put(5, 2);
        RAIN_LEVEL.put(10, 3);
        RAIN_LEVEL.put(15, 4);
        RAIN_LEVEL.put(30, 5);
        RAIN_LEVEL.put(70, 6);
        RAIN_LEVEL.put(140, 7);
    }

    /**
     * 根据雨量生成下雨级别 (12h)
     * @param rainfall
     * @return
     */
    public static Integer genRainLevel(Double rainfall) {
        for (Map.Entry<Integer, Integer> entry : RAIN_LEVEL.entrySet()) {
            if (rainfall < entry.getKey()) {
                return entry.getValue();
            }
        }
        return 8;
    }

    public static void main(String[] args) {
        StaticLog.info(String.valueOf(genRainLevel(0.9d)));
    }
}
